#include "CServo.h"
#include "WProgram.h"

CServo::CServo(int pin){
	_pin = pin;
	pinMode(_pin, OUTPUT);
}
void CServo::writeSpeed(int direction /*1=clockwise, 2=counterclockwise*/, int speedpercent /*0-100*/){
	if (direction == 1){
		clockwise_speed = ((speedpercent*-3.3)+1500);
		digitalWrite(_pin, HIGH);
		delayMicroseconds(clockwise_speed);
		digitalWrite(_pin, LOW);
		delay(20);
	}
	if (direction == 2){
		cclockwise_speed = ((speedpercent*2.7)+1500);
		digitalWrite(_pin, HIGH);
		delayMicroseconds(cclockwise_speed);
		digitalWrite(_pin, LOW);
		delay(20);
	}
}
void CServo::stop(){
	digitalWrite(_pin, HIGH);
	delayMicroseconds(1500);
	digitalWrite(_pin, LOW);
	delay(20);
}